package com.mjk.manager.magicapi.plugin.webservice.model;

import com.mjk.common.tools.springextend.BeeSpringBean;
import com.mjk.manager.magicapi.core.core.model.PathMagicEntity;
import com.mjk.manager.magicapi.plugin.task.model.TaskInfo;
import com.mjk.manager.magicapi.plugin.webservice.constns.MagicWebServiceConstns;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class WebServiceInfo extends PathMagicEntity {


    /**
     * webservice请求路径
     */
    private String path;

    /**
     * 名称
     */
    private String name;
    /**
     * 入参格式 1json 2xml
     */
    private String inType;
    /**
     * 出参格式 1json 2xml
     */
    private String outType;
    /**
     * 参数信息
     */
    private List<WebServiceParams> params;
    /**
     * 定时任务描述
     */
    private String description;
    /**
     * wsdl地址
     */
    private String wsdl;

    public List<WebServiceParams> getParams() {
        if (params == null) {
            params = new ArrayList<>();
        }
        return params;
    }
    public WebServiceInfo copy() {
        WebServiceInfo info = new WebServiceInfo();
        super.copyTo(info);
        info.setPath(this.path);
        info.setName(this.name);
        info.setInType(this.inType);
        info.setOutType(this.outType);
        info.setParams(this.params);
        info.setDescription(this.description);
        info.setWsdl(getWsdl(info.getGroupName(),info.getPath()));
        return info;
    }

    private String getWsdl(String groupName,String path){
        String port = BeeSpringBean.getEnvValue(MagicWebServiceConstns.SERVER_PORT);
        StringBuilder sb = new StringBuilder("http://localhost:");
        sb.append(port);
        sb.append("/"+ MagicWebServiceConstns.SERVER_FIX);
        sb.append("/"+groupName);
        sb.append("/"+path+"?wsdl");
        return sb.toString();
    }

}
